package oopcodeblock.codeblockDemo1;

public class Student {
    private String name;
    private int age;

    //写在成员位置的代码块
    //作用:可以把多个构造方法中重复的代码抽取出来

    //执行时机:每次创建对象时,都会优先执行该代码块,再执行构造方法
    //tips:该项技术已经渐渐淘汰了

    {
        System.out.println("开始创建对象了");
    }

    public Student() {
        System.out.println("无参构造方法");
    }

    public Student(String name, int age) {
        System.out.println("带参构造方法");
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
